| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 1 | # See www/CMake.html for instructions on how to build libcxx with CMake. |
| 2 | |
| 3 | #=============================================================================== |
| 4 | # Setup Project |
| 5 | #=============================================================================== |
| Chris Bieneman | cad86ff | 2016-05-31 20:21:52 | [diff] [blame] | 6 | cmake_minimum_required(VERSION 3.4.3) |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 7 | |
| Eric Fiselier | e9d4b23 | 2015-01-26 21:56:45 | [diff] [blame] | 8 | if(POLICY CMP0042) |
| 9 | cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default |
| 10 | endif() |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 11 | if(POLICY CMP0022) |
| 12 | cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang |
| 13 | endif() |
| 14 | |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 15 | # Add path for custom modules |
| 16 | set(CMAKE_MODULE_PATH |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 17 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 18 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" |
| Eric Fiselier | ce5695f | 2015-12-30 03:39:03 | [diff] [blame] | 19 | ${CMAKE_MODULE_PATH} |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 20 | ) |
| 21 | |
| Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 22 | |
| Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 | [diff] [blame] | 23 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 24 | project(libcxx CXX C) |
| 25 | |
| 26 | set(PACKAGE_NAME libcxx) |
| Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 | [diff] [blame] | 27 | set(PACKAGE_VERSION 4.0.0svn) |
| Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 28 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 29 | set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") |
| Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 | [diff] [blame] | 30 | |
| 31 | # Find the LLVM sources and simulate LLVM CMake options. |
| 32 | include(HandleOutOfTreeLLVM) |
| Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 | [diff] [blame] | 33 | endif() |
| Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 34 | |
| Saleem Abdulrasool | 7adfa03 | 2016-02-08 03:50:18 | [diff] [blame] | 35 | # Require out of source build. |
| 36 | include(MacroEnsureOutOfSourceBuild) |
| 37 | MACRO_ENSURE_OUT_OF_SOURCE_BUILD( |
| 38 | "${PROJECT_NAME} requires an out of source build. Please create a separate |
| 39 | build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." |
| 40 | ) |
| 41 | |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 42 | #=============================================================================== |
| 43 | # Setup CMake Options |
| 44 | #=============================================================================== |
| Eric Fiselier | 01609af | 2016-09-07 01:15:10 | [diff] [blame] | 45 | include(CMakeDependentOption) |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 46 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 47 | # Basic options --------------------------------------------------------------- |
| 48 | option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) |
| 49 | option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) |
| Petr Hosek | b640da0 | 2016-08-08 22:57:25 | [diff] [blame] | 50 | option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON) |
| Eric Fiselier | 5e4698c | 2016-05-03 21:30:18 | [diff] [blame] | 51 | option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON) |
| Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 | [diff] [blame] | 52 | option(LIBCXX_ENABLE_FILESYSTEM |
| 53 | "Build filesystem as part of libc++experimental.a" ${LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY}) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 54 | option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) |
| Eric Fiselier | 2d2f0c0 | 2016-10-30 22:53:00 | [diff] [blame] | 55 | |
| Eric Fiselier | 2d2f0c0 | 2016-10-30 22:53:00 | [diff] [blame] | 56 | # Benchmark options ----------------------------------------------------------- |
| Eric Fiselier | 0a799bd | 2016-08-29 19:50:49 | [diff] [blame] | 57 | option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependancies" ON) |
| Eric Fiselier | 2d2f0c0 | 2016-10-30 22:53:00 | [diff] [blame] | 58 | set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING |
| 59 | "Build the benchmarks against the specified native STL. |
| 60 | The value must be one of libc++/libstdc++") |
| 61 | set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING |
| 62 | "Use alternate GCC toolchain when building the native benchmarks") |
| 63 | |
| 64 | if (LIBCXX_BENCHMARK_NATIVE_STDLIB) |
| 65 | if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++" |
| 66 | OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")) |
| 67 | message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: " |
| 68 | "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'") |
| 69 | endif() |
| 70 | endif() |
| 71 | |
| Eric Fiselier | b9f425a | 2015-08-22 19:40:49 | [diff] [blame] | 72 | option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 73 | set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING |
| 74 | "Define suffix of library directory name (32/64)") |
| 75 | option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) |
| Eric Fiselier | 961269d | 2015-08-26 20:18:21 | [diff] [blame] | 76 | option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 77 | option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) |
| Eric Fiselier | 01609af | 2016-09-07 01:15:10 | [diff] [blame] | 78 | cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY |
| 79 | "Install libc++experimental.a" ON |
| 80 | "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF) |
| Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 | [diff] [blame] | 81 | set(LIBCXX_ABI_VERSION 1 CACHE STRING "ABI version of libc++.") |
| 82 | option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) |
| Saleem Abdulrasool | e146f75 | 2016-08-24 04:22:52 | [diff] [blame] | 83 | option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 84 | |
| Petr Hosek | b640da0 | 2016-08-08 22:57:25 | [diff] [blame] | 85 | if (NOT LIBCXX_ENABLE_SHARED AND NOT LIBCXX_ENABLE_STATIC) |
| 86 | message(FATAL_ERROR "libc++ must be built as either a shared or static library.") |
| 87 | endif() |
| 88 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 89 | # ABI Library options --------------------------------------------------------- |
| Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 | [diff] [blame] | 90 | set(LIBCXX_CXX_ABI "default" CACHE STRING |
| 91 | "Specify C++ ABI library to use.") |
| 92 | set(CXXABIS none default libcxxabi libcxxrt libstdc++ libsupc++) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 93 | set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) |
| 94 | |
| Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 | [diff] [blame] | 95 | # FIXME: This is a temporary hack to force LLVM buildbots to store |
| 96 | # the fixed cache entry instead of the previous cache entry. This is needed |
| 97 | # because some LLVM buildbots don't clear their cache. It will be removed |
| 98 | # once all LLVM bots have been run. |
| 99 | if (LIBCXX_CXX_ABI STREQUAL "") |
| 100 | set(LIBCXX_CXX_ABI "default" CACHE STRING |
| 101 | "Specify the C++ ABI library to use." FORCE) |
| 102 | endif() |
| 103 | |
| Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 104 | # Setup the default options if LIBCXX_CXX_ABI is not specified. |
| Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 | [diff] [blame] | 105 | if (LIBCXX_CXX_ABI STREQUAL "default") |
| Petr Hosek | d842fed | 2016-11-09 03:22:28 | [diff] [blame] | 106 | find_path( |
| 107 | LIBCXX_LIBCXXABI_INCLUDES_INTERNAL |
| 108 | cxxabi.h |
| 109 | PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi/include |
| 110 | ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi/include |
| 111 | NO_DEFAULT_PATH |
| 112 | ) |
| Chris Bieneman | 8c22696 | 2016-08-18 21:31:51 | [diff] [blame] | 113 | if (NOT DEFINED LIBCXX_STANDALONE_BUILD AND |
| Petr Hosek | d842fed | 2016-11-09 03:22:28 | [diff] [blame] | 114 | IS_DIRECTORY "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") |
| Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 115 | set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") |
| Petr Hosek | d842fed | 2016-11-09 03:22:28 | [diff] [blame] | 116 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") |
| Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 117 | set(LIBCXX_CXX_ABI_INTREE 1) |
| Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 | [diff] [blame] | 118 | else() |
| Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 | [diff] [blame] | 119 | set(LIBCXX_CXX_ABI_LIBNAME "default") |
| Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 | [diff] [blame] | 120 | endif() |
| 121 | else() |
| Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 122 | set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") |
| Eugene Zelenko | 96f1017 | 2016-08-08 18:01:50 | [diff] [blame] | 123 | endif() |
| Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 124 | |
| Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 125 | # Use a static copy of the ABI library when linking libc++. This option |
| 126 | # cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT. |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 127 | option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) |
| 128 | |
| Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 129 | # Generate and install a linker script inplace of libc++.so. The linker script |
| Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 130 | # will link libc++ to the correct ABI library. This option is on by default |
| 131 | # On UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' |
| Eric Fiselier | 5d5b59b | 2015-10-22 20:50:07 | [diff] [blame] | 132 | # is on. This option is also disabled when the ABI library is not specified |
| 133 | # or is specified to be "none". |
| Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 134 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) |
| Eric Fiselier | 1d3716a | 2015-10-15 23:04:54 | [diff] [blame] | 135 | if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY |
| Eric Fiselier | 1cf5a81 | 2015-10-22 20:54:27 | [diff] [blame] | 136 | AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" |
| Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 | [diff] [blame] | 137 | AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default" |
| Asiri Rathnayake | 10a6829 | 2016-05-14 23:58:11 | [diff] [blame] | 138 | AND PYTHONINTERP_FOUND |
| 139 | AND LIBCXX_ENABLE_SHARED) |
| Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 140 | set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) |
| 141 | endif() |
| 142 | |
| Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 143 | option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT |
| Eric Fiselier | bb856cc | 2015-10-15 22:41:51 | [diff] [blame] | 144 | "Use and install a linker script for the given ABI library" |
| Eric Fiselier | 1d3716a | 2015-10-15 23:04:54 | [diff] [blame] | 145 | ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) |
| Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 146 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 147 | # Build libc++abi with libunwind. We need this option to determine whether to |
| 148 | # link with libunwind or libgcc_s while running the test cases. |
| 149 | option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) |
| 150 | |
| 151 | # Target options -------------------------------------------------------------- |
| 152 | option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) |
| 153 | set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") |
| 154 | set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") |
| 155 | |
| 156 | # Feature options ------------------------------------------------------------- |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 157 | option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) |
| 158 | option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) |
| Ed Schouten | b33ae5b | 2015-03-12 15:44:39 | [diff] [blame] | 159 | option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) |
| Ed Schouten | abd06b4 | 2015-03-26 14:35:46 | [diff] [blame] | 160 | option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) |
| 161 | option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) |
| Eric Fiselier | 7330ed3 | 2014-12-06 21:02:58 | [diff] [blame] | 162 | option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) |
| Ed Schouten | 323ade3 | 2015-06-24 08:44:38 | [diff] [blame] | 163 | option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) |
| Eric Fiselier | 7330ed3 | 2014-12-06 21:02:58 | [diff] [blame] | 164 | option(LIBCXX_ENABLE_MONOTONIC_CLOCK |
| 165 | "Build libc++ with support for a monotonic clock. |
| Jonathan Roelofs | 5e91fa1 | 2015-08-24 21:20:07 | [diff] [blame] | 166 | This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) |
| Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 | [diff] [blame] | 167 | option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) |
| Ben Craig | 5163e46 | 2016-05-25 17:40:09 | [diff] [blame] | 168 | option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) |
| Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 | [diff] [blame] | 169 | option(LIBCXX_HAS_EXTERNAL_THREAD_API |
| 170 | "Build libc++ with an externalized threading API. |
| 171 | This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF) |
| Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 | [diff] [blame] | 172 | option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY |
| 173 | "Build libc++ with an externalized threading library. |
| 174 | This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 175 | |
| 176 | # Misc options ---------------------------------------------------------------- |
| Eric Fiselier | cb23a49 | 2015-10-10 03:34:52 | [diff] [blame] | 177 | # FIXME: Turn -pedantic back ON. It is currently off because it warns |
| 178 | # about #include_next which is used everywhere. |
| 179 | option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 180 | option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
| Saleem Abdulrasool | ab008f7 | 2016-07-12 14:39:13 | [diff] [blame] | 181 | option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 182 | |
| Eric Fiselier | bf9653d | 2015-03-31 04:15:45 | [diff] [blame] | 183 | option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) |
| 184 | set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 185 | "The Profile-rt library used to build with code coverage") |
| 186 | |
| Eric Fiselier | 961269d | 2015-08-26 20:18:21 | [diff] [blame] | 187 | # Don't allow a user to accidentally overwrite the system libc++ installation on Darwin. |
| 188 | # If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++ |
| 189 | # will not be generated and a warning will be issued. |
| 190 | option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF) |
| 191 | mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default. |
| 192 | |
| 193 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL) |
| 194 | if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr") |
| 195 | message(WARNING "Disabling libc++ install rules because installation would " |
| 196 | "overwrite the systems installation. Configure with " |
| 197 | "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.") |
| 198 | mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option. |
| 199 | set(LIBCXX_INSTALL_HEADERS OFF) |
| 200 | set(LIBCXX_INSTALL_LIBRARY OFF) |
| 201 | endif() |
| 202 | endif() |
| 203 | |
| Eric Fiselier | 85df7a8 | 2015-12-16 23:41:05 | [diff] [blame] | 204 | set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF) |
| 205 | if (XCODE OR MSVC_IDE) |
| 206 | set(LIBCXX_CONFIGURE_IDE_DEFAULT ON) |
| 207 | endif() |
| 208 | option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" |
| 209 | ${LIBCXX_CONFIGURE_IDE_DEFAULT}) |
| 210 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 211 | #=============================================================================== |
| 212 | # Check option configurations |
| 213 | #=============================================================================== |
| 214 | |
| Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 | [diff] [blame] | 215 | if (LIBCXX_ENABLE_FILESYSTEM AND NOT LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) |
| 216 | message(FATAL_ERROR |
| 217 | "LIBCXX_ENABLE_FILESYSTEM cannot be turned on when LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF") |
| 218 | endif() |
| 219 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 220 | # Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when |
| 221 | # LIBCXX_ENABLE_THREADS is on. |
| 222 | if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) |
| 223 | message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" |
| 224 | " when LIBCXX_ENABLE_THREADS is also set to OFF.") |
| Eric Fiselier | 25a1516 | 2014-08-18 05:03:46 | [diff] [blame] | 225 | endif() |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 226 | |
| Asiri Rathnayake | e262e7b | 2017-01-03 12:59:50 | [diff] [blame] | 227 | if(NOT LIBCXX_ENABLE_THREADS) |
| 228 | if(LIBCXX_HAS_PTHREAD_API) |
| 229 | message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON" |
| 230 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 231 | endif() |
| 232 | if(LIBCXX_HAS_EXTERNAL_THREAD_API) |
| 233 | message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON" |
| 234 | " when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 235 | endif() |
| Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 | [diff] [blame] | 236 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) |
| 237 | message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set " |
| 238 | "to ON when LIBCXX_ENABLE_THREADS is also set to ON.") |
| 239 | endif() |
| 240 | |
| 241 | endif() |
| 242 | |
| 243 | if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_HAS_EXTERNAL_THREAD_API) |
| 244 | message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and " |
| 245 | "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at " |
| 246 | "the same time") |
| Ben Craig | 5163e46 | 2016-05-25 17:40:09 | [diff] [blame] | 247 | endif() |
| 248 | |
| Asiri Rathnayake | e262e7b | 2017-01-03 12:59:50 | [diff] [blame] | 249 | if(LIBCXX_HAS_PTHREAD_API AND LIBCXX_HAS_EXTERNAL_THREAD_API) |
| 250 | message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" |
| 251 | "and LIBCXX_HAS_PTHREAD_API cannot be both" |
| 252 | "set to ON at the same time.") |
| Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 | [diff] [blame] | 253 | endif() |
| 254 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 255 | # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE |
| 256 | # is ON. |
| 257 | if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) |
| 258 | message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") |
| 259 | endif() |
| 260 | |
| 261 | # Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) |
| 262 | # and check that we can build with 32 bits if requested. |
| 263 | if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) |
| 264 | if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM |
| 265 | message(STATUS "Building 32 bits executables and libraries.") |
| 266 | endif() |
| 267 | elseif(LIBCXX_BUILD_32_BITS) |
| 268 | message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") |
| 269 | endif() |
| 270 | |
| 271 | # Check that this option is not enabled on Apple and emit a usage warning. |
| Eric Fiselier | c0b166e | 2015-03-03 15:59:51 | [diff] [blame] | 272 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 273 | if (APPLE) |
| 274 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") |
| 275 | else() |
| 276 | message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") |
| 277 | endif() |
| Eric Fiselier | 60479ea | 2016-11-18 19:53:45 | [diff] [blame] | 278 | if (LIBCXX_ENABLE_STATIC AND NOT PYTHONINTERP_FOUND) |
| 279 | message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.") |
| 280 | endif() |
| Eric Fiselier | c0b166e | 2015-03-03 15:59:51 | [diff] [blame] | 281 | endif() |
| 282 | |
| Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 283 | if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 284 | if (APPLE) |
| 285 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets") |
| 286 | endif() |
| 287 | if (NOT PYTHONINTERP_FOUND) |
| 288 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT requires python but it was not found.") |
| 289 | endif() |
| Asiri Rathnayake | 10a6829 | 2016-05-14 23:58:11 | [diff] [blame] | 290 | if (NOT LIBCXX_ENABLE_SHARED) |
| 291 | message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.") |
| 292 | endif() |
| Eric Fiselier | 8cbf020 | 2015-10-14 19:54:03 | [diff] [blame] | 293 | endif() |
| 294 | |
| 295 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) |
| 296 | message(FATAL_ERROR "Conflicting options given. |
| 297 | LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with |
| 298 | LIBCXX_ENABLE_ABI_LINKER_SCRIPT") |
| 299 | endif() |
| 300 | |
| Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 | [diff] [blame] | 301 | if (LIBCXX_HAS_MUSL_LIBC AND NOT LIBCXX_INSTALL_SUPPORT_HEADERS) |
| 302 | message(FATAL_ERROR "LIBCXX_INSTALL_SUPPORT_HEADERS can not be turned off" |
| 303 | "when building for Musl with LIBCXX_HAS_MUSL_LIBC.") |
| 304 | endif() |
| 305 | |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 306 | #=============================================================================== |
| 307 | # Configure System |
| 308 | #=============================================================================== |
| 309 | |
| Eric Fiselier | 4778eed | 2014-12-20 03:16:55 | [diff] [blame] | 310 | set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER}) |
| 311 | set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 312 | set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| Chandler Carruth | 7a033ca | 2014-12-29 12:15:47 | [diff] [blame] | 313 | set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) |
| Eric Fiselier | 4778eed | 2014-12-20 03:16:55 | [diff] [blame] | 314 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 315 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 316 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) |
| 317 | |
| Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 | [diff] [blame] | 318 | # Declare libc++ configuration variables. |
| 319 | # They are intended for use as follows: |
| 320 | # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. |
| 321 | # LIBCXX_COMPILE_FLAGS: Compile only flags. |
| 322 | # LIBCXX_LINK_FLAGS: Linker only flags. |
| Eric Fiselier | 3bf8a9c | 2016-10-09 21:34:03 | [diff] [blame] | 323 | # LIBCXX_LIBRARIES: libraries libc++ is linked to. |
| 324 | # LIBCXX_INTERFACE_LIBRARIES: Libraries that must be linked when using libc++ |
| Eric Fiselier | 742d878 | 2016-10-10 14:45:06 | [diff] [blame] | 325 | # These libraries are exposed in the linker script. |
| Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 | [diff] [blame] | 326 | set(LIBCXX_COMPILE_FLAGS "") |
| 327 | set(LIBCXX_LINK_FLAGS "") |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 328 | set(LIBCXX_LIBRARIES "") |
| Eric Fiselier | 3bf8a9c | 2016-10-09 21:34:03 | [diff] [blame] | 329 | set(LIBCXX_INTERFACE_LIBRARIES "") |
| Eric Fiselier | 8e2855c | 2014-11-15 06:26:30 | [diff] [blame] | 330 | |
| Eric Fiselier | a27cbf8 | 2016-06-02 01:10:08 | [diff] [blame] | 331 | # Include macros for adding and removing libc++ flags. |
| 332 | include(HandleLibcxxFlags) |
| 333 | |
| 334 | # Target flags ================================================================ |
| 335 | # These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that |
| 336 | # 'config-ix' use them during feature checks. It also adds them to both |
| 337 | # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' |
| 338 | add_target_flags_if(LIBCXX_BUILD_32_BITS "-m32") |
| 339 | add_target_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}") |
| 340 | add_target_flags_if(LIBCXX_SYSROOT "--sysroot=${LIBCXX_SYSROOT}") |
| 341 | add_target_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") |
| Eric Fiselier | 6e467a8 | 2016-11-13 22:27:00 | [diff] [blame] | 342 | if (LIBCXX_TARGET_TRIPLE) |
| 343 | set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}") |
| 344 | endif() |
| Eric Fiselier | a27cbf8 | 2016-06-02 01:10:08 | [diff] [blame] | 345 | |
| Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 | [diff] [blame] | 346 | # Configure compiler. |
| 347 | include(config-ix) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 348 | |
| Saleem Abdulrasool | e146f75 | 2016-08-24 04:22:52 | [diff] [blame] | 349 | if (LIBCXX_USE_COMPILER_RT) |
| 350 | list(APPEND LIBCXX_LINK_FLAGS "-rtlib=compiler-rt") |
| 351 | endif() |
| 352 | |
| Eric Fiselier | bf9653d | 2015-03-31 04:15:45 | [diff] [blame] | 353 | # Configure coverage options. |
| 354 | if (LIBCXX_GENERATE_COVERAGE) |
| 355 | include(CodeCoverage) |
| 356 | set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) |
| 357 | endif() |
| Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 | [diff] [blame] | 358 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 359 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 360 | |
| Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 | [diff] [blame] | 361 | #=============================================================================== |
| 362 | # Setup Compiler Flags |
| 363 | #=============================================================================== |
| 364 | |
| JF Bastien | c7c4c77 | 2016-03-05 14:22:02 | [diff] [blame] | 365 | include(HandleLibCXXABI) # Setup the ABI library flags |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 366 | |
| Michal Gorny | b79ca0a | 2016-09-27 07:55:26 | [diff] [blame] | 367 | if (NOT LIBCXX_STANDALONE_BUILD) |
| 368 | # Remove flags that may have snuck in. |
| 369 | remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG |
| 370 | -lc++abi -m32) |
| 371 | endif() |
| 372 | remove_flags(-stdlib=libc++ -stdlib=libstdc++) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 373 | |
| Eric Fiselier | 499d878 | 2015-10-13 23:56:33 | [diff] [blame] | 374 | # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. |
| Eric Fiselier | 7b081f6 | 2015-10-15 20:27:15 | [diff] [blame] | 375 | # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors |
| 376 | # so they don't get transformed into -Wno and -errors respectivly. |
| 377 | remove_flags(-Wno-pedantic -pedantic-errors -pedantic) |
| Eric Fiselier | 499d878 | 2015-10-13 23:56:33 | [diff] [blame] | 378 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 379 | # Required flags ============================================================== |
| Eric Fiselier | c9e74dd | 2016-08-14 22:51:54 | [diff] [blame] | 380 | set(LIBCXX_STANDARD_VER c++11 CACHE INTERNAL "internal option to change build dialect") |
| Petr Hosek | 44197a1 | 2016-10-23 21:48:27 | [diff] [blame] | 381 | if (LIBCXX_HAS_MUSL_LIBC) |
| 382 | # musl's pthread implementations uses volatile types in their structs which is |
| 383 | # not a constexpr in C++11 but is in C++14, so we use C++14 with musl. |
| 384 | set(LIBCXX_STANDARD_VER c++14 CACHE INTERNAL "internal option to change build dialect") |
| 385 | endif() |
| Eric Fiselier | c9e74dd | 2016-08-14 22:51:54 | [diff] [blame] | 386 | add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER}) |
| 387 | mangle_name("LIBCXX_SUPPORTS_STD_EQ_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME) |
| Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 | [diff] [blame] | 388 | if(NOT ${SUPPORTS_DIALECT_NAME}) |
| 389 | if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 390 | message(FATAL_ERROR "C++11 or greater is required but the compiler does not support ${LIBCXX_STANDARD_VER}") |
| 391 | endif() |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 392 | endif() |
| 393 | |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 394 | # On all systems the system c++ standard library headers need to be excluded. |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 395 | # MSVC only has -X, which disables all default includes; including the crt. |
| 396 | # Thus, we do nothing and hope we don't accidentally include any of the C++ |
| 397 | # headers |
| 398 | add_compile_flags_if_supported(-nostdinc++) |
| Eric Fiselier | d74dee9 | 2015-07-29 21:07:28 | [diff] [blame] | 399 | |
| Eric Fiselier | 8330b1e | 2016-10-25 19:43:44 | [diff] [blame] | 400 | # Hide all inline function definitions which have not explicitly been marked |
| 401 | # visible. This prevents new definitions for inline functions from appearing in |
| 402 | # the dylib when get ODR used by another function. |
| 403 | add_compile_flags_if_supported(-fvisibility-inlines-hidden) |
| 404 | |
| Eric Fiselier | 74c9857 | 2016-09-26 22:19:41 | [diff] [blame] | 405 | # Let the library headers know they are currently being used to build the |
| 406 | # library. |
| Eric Fiselier | 6dbed46 | 2016-09-16 00:00:48 | [diff] [blame] | 407 | add_definitions(-D_LIBCPP_BUILDING_LIBRARY) |
| 408 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 409 | # Warning flags =============================================================== |
| Eric Fiselier | 692177d | 2015-07-18 20:40:46 | [diff] [blame] | 410 | add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 411 | add_compile_flags_if_supported( |
| Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 | [diff] [blame] | 412 | -Wall -Wextra -W -Wwrite-strings |
| 413 | -Wno-unused-parameter -Wno-long-long |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 414 | -Werror=return-type) |
| Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 | [diff] [blame] | 415 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
| 416 | add_compile_flags_if_supported( |
| 417 | -Wno-user-defined-literals |
| 418 | -Wno-covered-switch-default) |
| 419 | elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") |
| 420 | add_compile_flags_if_supported( |
| Eric Fiselier | 3ec6b84 | 2016-08-29 20:43:38 | [diff] [blame] | 421 | -Wno-literal-suffix |
| 422 | -Wno-c++14-compat) |
| 423 | endif() |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 424 | if (LIBCXX_ENABLE_WERROR) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 425 | add_compile_flags_if_supported(-Werror) |
| 426 | add_compile_flags_if_supported(-WX) |
| Eric Fiselier | 26d2390 | 2015-07-31 01:25:01 | [diff] [blame] | 427 | else() |
| 428 | # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is |
| 429 | # added elsewhere. |
| 430 | add_compile_flags_if_supported(-Wno-error) |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 431 | endif() |
| 432 | if (LIBCXX_ENABLE_PEDANTIC) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 433 | add_compile_flags_if_supported(-pedantic) |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 434 | endif() |
| Saleem Abdulrasool | ab008f7 | 2016-07-12 14:39:13 | [diff] [blame] | 435 | if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS) |
| 436 | add_definitions(-D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) |
| 437 | endif() |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 438 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 439 | # Exception flags ============================================================= |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 440 | if (LIBCXX_ENABLE_EXCEPTIONS) |
| 441 | # Catches C++ exceptions only and tells the compiler to assume that extern C |
| 442 | # functions never throw a C++ exception. |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 443 | add_compile_flags_if_supported(-EHsc) |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 444 | else() |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 445 | add_definitions(-D_LIBCPP_NO_EXCEPTIONS) |
| 446 | add_compile_flags_if_supported(-EHs- -EHa-) |
| 447 | add_compile_flags_if_supported(-fno-exceptions) |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 448 | endif() |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 449 | |
| 450 | # RTTI flags ================================================================== |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 451 | if (NOT LIBCXX_ENABLE_RTTI) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 452 | add_definitions(-D_LIBCPP_NO_RTTI) |
| 453 | add_compile_flags_if_supported(-GR-) |
| 454 | add_compile_flags_if_supported(-fno-rtti) |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 455 | endif() |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 456 | |
| Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 | [diff] [blame] | 457 | # Threading flags ============================================================= |
| 458 | if (LIBCXX_HAS_EXTERNAL_THREAD_API AND LIBCXX_ENABLE_SHARED) |
| 459 | # Need to allow unresolved symbols if this is to work with shared library builds |
| 460 | if (APPLE) |
| 461 | add_link_flags("-undefined dynamic_lookup") |
| 462 | else() |
| 463 | # Relax this restriction from HandleLLVMOptions |
| 464 | string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") |
| 465 | endif() |
| 466 | endif() |
| 467 | |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 468 | # Assertion flags ============================================================= |
| 469 | define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) |
| 470 | define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) |
| Howard Hinnant | e103a3d | 2012-08-05 17:37:39 | [diff] [blame] | 471 | if (LIBCXX_ENABLE_ASSERTIONS) |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 472 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 473 | define_if_not(MSVC -D_DEBUG) |
| Howard Hinnant | 4a0e74f | 2013-02-25 15:50:36 | [diff] [blame] | 474 | endif() |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 475 | |
| Eric Fiselier | 29026ad | 2016-10-14 12:56:52 | [diff] [blame] | 476 | # Modules flags =============================================================== |
| 477 | # FIXME The libc++ sources are fundamentally non-modular. They need special |
| 478 | # versions of the headers in order to provide C++03 and legacy ABI definitions. |
| 479 | # NOTE: The public headers can be used with modules in all other contexts. |
| 480 | if (LLVM_ENABLE_MODULES) |
| 481 | # Ignore that the rest of the modules flags are now unused. |
| 482 | add_compile_flags_if_supported(-Wno-unused-command-line-argument) |
| 483 | add_compile_flags(-fno-modules) |
| 484 | endif() |
| 485 | |
| Jonathan Roelofs | 5e91fa1 | 2015-08-24 21:20:07 | [diff] [blame] | 486 | # Sanitizer flags ============================================================= |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 487 | |
| Chris Bieneman | 8c22696 | 2016-08-18 21:31:51 | [diff] [blame] | 488 | # Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 489 | # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. |
| Chris Bieneman | 8c22696 | 2016-08-18 21:31:51 | [diff] [blame] | 490 | if (LIBCXX_STANDALONE_BUILD) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 491 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 492 | "Define the sanitizer used to build the library and tests") |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 493 | # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. |
| 494 | # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. |
| 495 | if (LLVM_USE_SANITIZER AND NOT MSVC) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 496 | add_flags_if_supported("-fno-omit-frame-pointer") |
| 497 | add_flags_if_supported("-gline-tables-only") |
| 498 | |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 499 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND |
| 500 | NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 501 | add_flags_if_supported("-gline-tables-only") |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 502 | endif() |
| 503 | if (LLVM_USE_SANITIZER STREQUAL "Address") |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 504 | add_flags("-fsanitize=address") |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 505 | elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 506 | add_flags(-fsanitize=memory) |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 507 | if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 508 | add_flags("-fsanitize-memory-track-origins") |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 509 | endif() |
| 510 | elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 511 | add_flags("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 512 | elseif (LLVM_USE_SANITIZER STREQUAL "Thread") |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 513 | add_flags(-fsanitize=thread) |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 514 | else() |
| 515 | message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") |
| 516 | endif() |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 517 | elseif(LLVM_USE_SANITIZER AND MSVC) |
| 518 | message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") |
| Eric Fiselier | 5514d36 | 2015-07-29 23:46:55 | [diff] [blame] | 519 | endif() |
| 520 | endif() |
| Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 521 | |
| 522 | # Configuration file flags ===================================================== |
| Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 | [diff] [blame] | 523 | if (NOT LIBCXX_ABI_VERSION EQUAL "1") |
| 524 | config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) |
| 525 | endif() |
| 526 | config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) |
| 527 | |
| Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 528 | config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) |
| 529 | config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) |
| 530 | config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT) |
| 531 | config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) |
| 532 | config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) |
| 533 | config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) |
| 534 | |
| Ben Craig | 5163e46 | 2016-05-25 17:40:09 | [diff] [blame] | 535 | config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD) |
| Asiri Rathnayake | 040945b | 2016-09-11 21:46:40 | [diff] [blame] | 536 | config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL) |
| Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 | [diff] [blame] | 537 | config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) |
| Vasileios Kalintiris | 579b42b | 2015-11-09 10:21:04 | [diff] [blame] | 538 | config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) |
| 539 | |
| Eric Fiselier | 74c9857 | 2016-09-26 22:19:41 | [diff] [blame] | 540 | # By default libc++ on Windows expects to use a shared library, which requires |
| 541 | # the headers to use DLL import/export semantics. However when building a |
| 542 | # static library only we modify the headers to disable DLL import/export. |
| 543 | if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) |
| 544 | message(STATUS "Generating custom __config for non-DLL Windows build") |
| Shoaib Meenai | c6d8e8a | 2016-12-05 19:40:12 | [diff] [blame] | 545 | config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| Eric Fiselier | 74c9857 | 2016-09-26 22:19:41 | [diff] [blame] | 546 | endif() |
| 547 | |
| Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 548 | if (LIBCXX_NEEDS_SITE_CONFIG) |
| Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 | [diff] [blame] | 549 | configure_file("include/__config_site.in" |
| 550 | "${LIBCXX_BINARY_DIR}/__config_site" |
| 551 | @ONLY) |
| 552 | |
| Eric Fiselier | a662279 | 2015-10-14 00:22:05 | [diff] [blame] | 553 | # Provide the config definitions by included the generated __config_site |
| 554 | # file at compile time. |
| Saleem Abdulrasool | 1ca3c45 | 2017-01-01 20:20:40 | [diff] [blame] | 555 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 556 | add_compile_flags("/FI\"${LIBCXX_BINARY_DIR}/__config_site\"") |
| 557 | else() |
| 558 | add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site") |
| 559 | endif() |
| Eric Fiselier | 73ffc78 | 2015-10-13 22:12:02 | [diff] [blame] | 560 | endif() |
| 561 | |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 562 | #=============================================================================== |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 563 | # Setup Source Code And Tests |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 564 | #=============================================================================== |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 565 | include_directories(include) |
| Howard Hinnant | c4962b3 | 2013-11-15 17:18:57 | [diff] [blame] | 566 | add_subdirectory(include) |
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 | [diff] [blame] | 567 | add_subdirectory(lib) |
| Eric Fiselier | b9f425a | 2015-08-22 19:40:49 | [diff] [blame] | 568 | |
| Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 | [diff] [blame] | 569 | |
| Eric Fiselier | d9b9ef7 | 2016-07-19 23:07:03 | [diff] [blame] | 570 | if (LIBCXX_INCLUDE_BENCHMARKS) |
| 571 | add_subdirectory(benchmarks) |
| 572 | endif() |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 573 | if (LIBCXX_INCLUDE_TESTS) |
| 574 | add_subdirectory(test) |
| Eric Fiselier | 5e000c6 | 2016-11-14 02:43:12 | [diff] [blame] | 575 | add_subdirectory(lib/abi) |
| Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 | [diff] [blame] | 576 | endif() |
| Eric Fiselier | b9f425a | 2015-08-22 19:40:49 | [diff] [blame] | 577 | if (LIBCXX_INCLUDE_DOCS) |
| 578 | add_subdirectory(docs) |
| 579 | endif() |